
include_directories(
        ${CMAKE_CURRENT_SOURCE_DIR}/src
)

file(GLOB BLF_SOURCE
        ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
)

if (WIN32)
    message("use system is  " ${CMAKE_HOST_SYSTEM_NAME})
    if (MSVC)
        message(STATUS "Set MSVC file encoding to utf-8.")
        add_compile_options(/utf-8 /EHsc)
        # https://learn.microsoft.com/zh-tw/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170
        message(STATUS "Set MSVC Windows SDK to Windows 10.")
        add_compile_definitions(_WIN32_WINNT=0x0A00)
    endif ()

    set(BLF_LIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/windows/Vector_BLF.lib)
    include_directories(
            ${CMAKE_CURRENT_SOURCE_DIR}/include/windows
            ${CMAKE_CURRENT_SOURCE_DIR}/include/windows/Vector
            ${CMAKE_SOURCE_DIR}/src
    )
    add_library(ycblf STATIC ${BLF_SOURCE})
#elseif (UNIX)
#    message("use system is  " ${CMAKE_HOST_SYSTEM_NAME})
#    set(BLF_LIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/libVector_BLF.so)
#    include_directories(
#            ${CMAKE_CURRENT_SOURCE_DIR}/include/linux
#            ${CMAKE_CURRENT_SOURCE_DIR}/include/linux/Vector
#            ${CMAKE_SOURCE_DIR}/src
#    )
#    add_library(ycblf SHARED ${BLF_SOURCE})
else ()
    message("use system is aarch64")
    set(BLF_LIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/aarch64/libVector_BLF.so)
    include_directories(
            ${CMAKE_CURRENT_SOURCE_DIR}/include/aarch64
            ${CMAKE_CURRENT_SOURCE_DIR}/include/aarch64/Vector
            ${CMAKE_SOURCE_DIR}/src
    )
    add_library(ycblf SHARED ${BLF_SOURCE})
endif ()

# 设置库的输出路径
set_target_properties(ycblf PROPERTIES
        ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/output/blf/lib" # 静态库的输出路径
        LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/output/blf/lib" # 动态库的输出路径 (.so/.dll)
        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/output/blf/lib" # 可执行文件路径（用于动态库 .dll 的运行时）
)

target_link_libraries(ycblf ${BLF_LIB})

add_executable(ycblf_demo ycblf_demo.cpp)
target_link_libraries(ycblf_demo ycblf -lpthread)

set_target_properties(ycblf_demo PROPERTIES
        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/output/blf/bin"
)

# 拷贝 yccan.h 到输出目录
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/ycblf.h DESTINATION ${CMAKE_SOURCE_DIR}/output/blf/include)
